<template>
    <div>
    </div>
</template>
<script setup>
import { onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { codeLogin,getInfo } from '../../api/auth/index'
import {setAuthCache } from '../../utils/system/auth'

const router = useRouter()
const route = useRoute()

//获取code
const code = route.query.code;

if (!code) {
    // window.location.href = 'https://sit-cloud.zhinengjianshe.com/'
    //刷新当前页面
    // window.location.reload()
    alert('缺少code')
} else {
    codeLogin(code).then((res) => {
        console.log(res, "res");
        setAuthCache('Authorization',res.data.data)
        // localStorage.setItem('Authorization', res.data.data)
        getInfo().then(res => {
            const data = JSON.stringify(res.data)
            // localStorage.setItem('userInfo', data)
            setAuthCache('userInfo', data)
            router.push('/news')
        })
    });
}

</script>